﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql;
using MySql.Data.MySqlClient;
using System.Data;
using MySql.Data;
using System.Configuration;


namespace TweetJSON.DAL
{
    class MySQLClient
    {
        public MySQLClient()
        {
           
        }

        public DataTable getData(string command)
        {
            DataTable dt = null;

            using (MySqlConnection connection = new MySqlConnection(ConfigurationManager.AppSettings["ConnectionString"]))
            {
                using (MySqlDataAdapter adapter = new MySqlDataAdapter(command, connection))
                {
                    connection.Open();
                    adapter.SelectCommand.CommandType = CommandType.Text;

                    dt = new DataTable();
                    adapter.Fill(dt);
                    connection.Close();
                }

            }
            return dt;
        }

        public void InsertData(string command)
        {
            using (MySqlConnection connection = new MySqlConnection(ConfigurationManager.AppSettings["ConnectionString"]))
            {
                using (MySqlCommand myCommmand = new MySqlCommand(command, connection))
                {
                    connection.Open();
                    try
                    {

                        myCommmand.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        if (ex.Message.Contains("Duplicate"))
                        {

                        }
                        else
                        {

                        }
                    }
                    connection.Close();
                }

            }
        }
 
    }
}
